import java.util.LinkedList;

public class Offer6 {
    public int[] reversePrint(ListNode head) {
        LinkedList<Integer> integers = new LinkedList<>();
        while (head!=null){
            integers.addLast(head.val);
            head=head.next;
        }
        int[] ints = new int[integers.size()];
        Object[] objects = integers.toArray();
        for (int i = 0; i < objects.length; i++) {
            ints[i] = (Integer)objects[objects.length-i-1];
        }
        return ints;
    }
}
